import format from '@dfeidao/atom-web/dt/format';
import parse from '@dfeidao/atom-web/dt/parse';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p003 from './p003';
import p004 from './p004';
export default async function a005(fd: IFeidaoAiBrowserComponent) {
	// todo
	const dept1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="dept"]');
	let dept = "";
	if (dept1.selectedIndex > 0) {
		dept = dept1.selectedOptions[0].text;
	}
	const project1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="project"]');
	let project = "";
	if (project1.selectedIndex > 0) {
		project = project1.selectedOptions[0].text;
	}
	const risk_type1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_type"]');
	const risk_type2 = risk_type1.value;
	let risk_type = "";
	if (risk_type2 !== "") {
		risk_type = risk_type2;
	}
	const risk_status1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_status"]');
	const risk_status2 = risk_status1.value;
	let risk_status = "";
	if (risk_status2 !== "") {
		risk_status = risk_status2;
	}
	const time11 = fd.data.node.querySelector<HTMLInputElement>('[data-id="time1"]');
	const time111 = time11.value;
	const time1=parse(time111);
	let time112 = 0;
	if (time1 > 0) {
		time112 = time1;
	}
	const time21 = fd.data.node.querySelector<HTMLInputElement>('[data-id="time2"]');
	const time211 = time21.value;
	const time2=parse(time211);
	let time212 = 1000000000000000000000000;
	if (time1 > 0) {
		time212 = time2;
	}
	const res = await nodejs< Array<{ risk_no: string;create_time: number}>>('risk-control/zj-000001/s004', {
		filter: {
			dept,
			project,
			risk_type,
			risk_status,
			time112,
			time212,
			pn:1
		}
	});
	const rre = res.map((n) => {
		return { ...n, create_time: format(n.create_time, 2) };
	});
	const dtdata = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	const dtpn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	const dtNodata = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p004"]');
	dtpn.style.display = "none";
	if (res.length > 0) {
		render(fd, rre, p003, 'p003', "inner");
		dtdata.style.display = "block";
		dtNodata.style.display = "none";
	} else {
		render(fd,"",p004,'p004',"inner");
		dtdata.style.display = "none";
		dtNodata.style.display = "block";
	}
}
